#!/usr/bin/env bash
############################################
choose_which_gnu_linux_distro() {
	source ${TMOE_SHARE_DIR}/container/qemu/qemu-user
	RETURN_TO_WHERE='choose_which_gnu_linux_distro'
	RETURN_TO_MENU='choose_which_gnu_linux_distro'
	CLOUD_ROOTFS='false'
	DEB_BOOT_STRAP='false'
	TMOE_LINUX_CONTAINER_DISTRO=''
	check_rootfs_dir
	[[ ! -e ${CONFIG_FOLDER}/debootstrap_dir.txt ]] || rm -fv ${CONFIG_FOLDER}/debootstrap_dir.txt
	rm -f ~/.ALPINELINUXDetectionFILE 2>/dev/null
	unset NODE02_ENABLED WEEKLY_BUILD_CONTAINER
	choose_which_gnu_linux_distro_ja() {
		SELECTED_GNU_LINUX=$(whiptail --title "GNU/Linux distros" --menu "GNU/Linuxディストリビューションを選択してください" 0 50 0 \
			"1" "🍭 beta版:Weekly builds(GUI included)" \
			"2" "🍥 Debian は オペレーティングシステムのフリーなディストリビューションです" \
			"3" "🍛 Ubuntu:開発目標は「誰にでも使いやすい最新かつ安定したOS」を提供することである" \
			"4" "🌉 Arch:「シンプリシティ」、「ミニマリズム」、「エレガンス」さ、コードの正しさに焦点を当てて開発されている" \
			"5" "👒 Fedora:レッドハットが支援するコミュニティー「Fedora Project」によって開発されているRPM系Linux distro" \
			"6" "🍱 manjaro,centos,alpine,puppy" \
			"7" "🐉 Kali Rolling:ペネトレーションテストを主な目的としている" \
			"8" "🍊 Armbian:ARM開発ボード用のDebianおよびUbuntuベースのコンピューターオペレーティングシステムです" \
			"9" "🦎 chroot専属する:opensuse,deepin" \
			"10" "🍓 体験版,サポートされなくなりました:SteamOS,RaspiOS,Gentoo" \
			"0" "🌚 戻る" \
			3>&1 1>&2 2>&3)
	}
	choose_which_gnu_linux_distro_zh() {
		SELECTED_GNU_LINUX=$(whiptail --title "GNU/Linux distros" --menu "您想要安装哪个GNU/Linux发行版?" 0 50 0 \
			"1" "🍭 beta公测:Weekly builds(每周构建GUI版)" \
			"2" "🍥 Debian:致力于自由" \
			"3" "🍛 Ubuntu:我的存在是因為大家的存在" \
			"4" "🌉 Arch:系统设计以KISS为总体指导原则" \
			"5" "👒 Fedora:红帽社区版,新技术试验场" \
			"6" "🍱 manjaro,centos,alpine,puppy" \
			"7" "🐉 Kali Rolling:设计用于数字取证和渗透测试" \
			"8" "🍊 Armbian:香蕉派,香橙派(预装xfce)" \
			"9" "🦎 chroot专属:deepin,opensuse" \
			"10" "🍓 experimental(体验版,不再维护):SteamOS,RaspiOS" \
			"0" "🌚 Return to previous menu 返回上级菜单" \
			3>&1 1>&2 2>&3)
	}
	choose_which_gnu_linux_distro_en() {
		SELECTED_GNU_LINUX=$(whiptail --title "GNU/Linux distros" --menu "Which distribution do you want to install?" 0 50 0 \
			"1" "🍭 beta version:Weekly builds(GUI included)" \
			"2" "🍥 Debian is a distro composed of free and open-source software" \
			"3" "🍛 Ubuntu is the modern, open source OS." \
			"4" "🌉 Arch:simplicity,modernity,pragmatism,user centrality and versatility" \
			"5" "👒 Fedora:developed by the community-supported Fedora Project which is sponsored primarily by Red Hat" \
			"6" "🍱 manjaro,centos,alpine,puppy" \
			"7" "🐉 Kali is a Debian-derived distro designed for digital forensics and penetration testing" \
			"8" "🍊 Armbian:ARM development boards OS" \
			"9" "🦎 chroot exclusive:opensuse,deepin" \
			"10" "🍓 experimental,no longer maintained:SteamOS,RaspiOS,Gentoo" \
			"0" "🌚 Return to previous menu" \
			3>&1 1>&2 2>&3)
	}
	##############################
	case ${TMOE_MENU_LANG} in
	zh_*UTF-8) choose_which_gnu_linux_distro_zh ;;
	ja_JP.UTF-8) choose_which_gnu_linux_distro_ja ;;
	*) choose_which_gnu_linux_distro_en ;;
	esac

	case "${SELECTED_GNU_LINUX}" in
	0 | "") proot_container_menu ;;
	1) install_tmoe_weekly_build_edition ;;
	2) install_debian_gnu_linux_distro ;;
	3) install_ubuntu_gnu_linux_distro ;;
	4)
		DISTRO_NAME='arch'
		TMOE_LINUX_CONTAINER_DISTRO='arch'
		creat_container_edition_txt
		go_to_proot_management
		;;
	5) install_fedora_gnu_linux_distro ;;
	6) install_beta_containers ;;
	7)
		DISTRO_NAME='kali'
		DISTRO_CODE='rolling'
		TMOE_LINUX_CONTAINER_DISTRO='kali-rolling'
		creat_container_edition_txt
		go_to_proot_management
		;;
	8) install_armbian_linux_distro ;;
	9) install_chroot_exclusive_containers ;;
	10) install_alpha_containers ;;
	esac
	####################
	exit 0
}
##############################
install_tmoe_weekly_build_edition() {
	case ${ARCH_TYPE} in
	amd64 | i386 | arm64 | armhf) WEEKLY_BUILD_CONTAINER=true ;;
	*) distro_does_not_support ;;
	esac
	choose_de_en() {
		INSTALLDESKTOP=$(whiptail --title "Desktop environment" --menu \
			"TMOE/Azure Server will automatically build and release the latest DE container every week/month" 0 0 0 \
			"1" "🐭 xfce(elegant, high compatibility)" \
			"2" "🌿 mate(the continuation of GNOME 2)" \
			"3" "🦖 kde plasma5(beautiful and modern)" \
			"4" "🐦 lxqt" \
			"5" "🕊️ lxde(lightweight)" \
			"6" "zsh(nogui)" \
			"7" "Weekly schedule" \
			"0" "🌚 back =￣ω￣=" \
			3>&1 1>&2 2>&3)
	}
	choose_de_zh() {
		INSTALLDESKTOP=$(whiptail --title "Desktop environment" --menu \
			"tmoe/azure服务器每周都会自动构建并发布最新版,少部分发行版为每月更新" 0 0 0 \
			"1" "🐭 xfce(elegant, high compatibility)" \
			"2" "🌿 mate(the continuation of GNOME 2)" \
			"3" "🦖 kde plasma5(风格华丽的桌面环境)" \
			"4" "🐦 lxqt" \
			"5" "🕊️ lxde(轻量级)" \
			"6" "zsh(nogui)" \
			"7" "schedule 自动构建计划日程表" \
			"0" "🌚 back =￣ω￣=" \
			3>&1 1>&2 2>&3)
	}
	#"7" "Request specific version" \"7" "request 请求更新/增加版本" \
	case ${TMOE_MENU_LANG} in
	zh_*UTF-8) choose_de_zh ;;
	*) choose_de_en ;;
	esac
	case "${INSTALLDESKTOP}" in
	0 | "") choose_which_gnu_linux_distro ;;
	1)
		DESKTOP="xfce"
		choose_xfce_distro
		;;
	2)
		DESKTOP="mate"
		choose_mate_distro
		;;
	3)
		DESKTOP="kde"
		choose_kde_distro
		;;
	4)
		DESKTOP="lxqt"
		choose_lxqt_distro
		;;
	5)
		DESKTOP="lxde"
		choose_lxde_distro
		;;
	6)
		#printf "%s\n" "This feature may be available on 2020-02-17."
		DESKTOP="zsh"
		choose_zsh_distro
		;;
	7) view_the_schedule ;;
	999) request_weekly_build_version ;;
	esac
	press_enter_to_return
	install_tmoe_weekly_build_edition
}
request_weekly_build_version() {
	TMOE_LINUX_WEEKLY_BUILD_ISSUE_URL="https://gitee.com/mo2/linux/issues/I2EAVQ"
	printf "${BLUE}%s\n${RESET}" "${TMOE_LINUX_WEEKLY_BUILD_ISSUE_URL}"
	if [[ -e /mnt/c/WINDOWS/system32/cmd.exe ]]; then
		cd /mnt/c/Users
		/mnt/c/WINDOWS/system32/cmd.exe /c "start ${TMOE_LINUX_WEEKLY_BUILD_ISSUE_URL}"
		cd -
	fi
	case ${LINUX_DISTRO} in
	Android) am start -a android.intent.action.VIEW -d "${TMOE_LINUX_WEEKLY_BUILD_ISSUE_URL}" ;;
	*) su "${CURRENT_USER_NAME}" -c "xdg-open ${TMOE_LINUX_WEEKLY_BUILD_ISSUE_URL}" ;;
	esac
}
set_debian_sid_env() {
	DISTRO_NAME='debian'
	DISTRO_CODE="sid-${DESKTOP}"
	DISTRO_NAME_02=debian-sid
	NODE02_ENABLED=true
	#TMOE_LINUX_CONTAINER_DISTRO="${DISTRO_NAME}-${DISTRO_CODE}"
	TMOE_LINUX_CONTAINER_DISTRO=${DISTRO_NAME_02}
	creat_container_edition_txt
	go_to_proot_management
}
set_kali_rolling_env() {
	DISTRO_NAME='kali'
	DISTRO_CODE="rolling-${DESKTOP}"
	DISTRO_NAME_02=kali-rolling
	NODE02_ENABLED=true
	#TMOE_LINUX_CONTAINER_DISTRO="${DISTRO_NAME}-${DISTRO_CODE}"
	TMOE_LINUX_CONTAINER_DISTRO=${DISTRO_NAME_02}
	creat_container_edition_txt
	go_to_proot_management
}
set_ubuntu_dev_env() {
	DISTRO_NAME='ubuntu'
	DISTRO_CODE="dev-${DESKTOP}"
	DISTRO_NAME_02=ubuntu-dev
	NODE02_ENABLED=true
	#TMOE_LINUX_CONTAINER_DISTRO="${DISTRO_NAME}-${DISTRO_CODE}"
	TMOE_LINUX_CONTAINER_DISTRO=${DISTRO_NAME_02}
	creat_container_edition_txt
	go_to_proot_management
}
set_mint_tricia_env() {
	DISTRO_NAME='mint'
	DISTRO_CODE="tricia-${DESKTOP}"
	DISTRO_NAME_02=mint-tricia
	NODE02_ENABLED=true
	#TMOE_LINUX_CONTAINER_DISTRO="${DISTRO_NAME}-${DISTRO_CODE}"
	TMOE_LINUX_CONTAINER_DISTRO=${DISTRO_NAME_02}
	creat_container_edition_txt
	go_to_proot_management
}
set_mint_ulyssa_env() {
	DISTRO_NAME='mint'
	DISTRO_CODE="ulyssa-${DESKTOP}"
	DISTRO_NAME_02=mint-ulyssa
	NODE02_ENABLED=true
	#TMOE_LINUX_CONTAINER_DISTRO="${DISTRO_NAME}-${DISTRO_CODE}"
	TMOE_LINUX_CONTAINER_DISTRO=${DISTRO_NAME_02}
	creat_container_edition_txt
	go_to_proot_management
}
set_alpine_edge_env() {
	DISTRO_NAME='alpine'
	DISTRO_CODE="edge-${DESKTOP}"
	DISTRO_NAME_02=alpine-edge
	NODE02_ENABLED=false
	#TMOE_LINUX_CONTAINER_DISTRO="${DISTRO_NAME}-${DISTRO_CODE}"
	TMOE_LINUX_CONTAINER_DISTRO=${DISTRO_NAME_02}
	creat_container_edition_txt
	go_to_proot_management
}
set_fedora_rawhide_env() {
	DISTRO_NAME='fedora'
	DISTRO_CODE="rawhide-${DESKTOP}"
	DISTRO_NAME_02=fedora-rawhide
	NODE02_ENABLED=false
	#TMOE_LINUX_CONTAINER_DISTRO="${DISTRO_NAME}-${DISTRO_CODE}"
	TMOE_LINUX_CONTAINER_DISTRO=${DISTRO_NAME_02}
	creat_container_edition_txt
	go_to_proot_management
}
set_ubuntu_bionic_env() {
	DISTRO_NAME='ubuntu'
	DISTRO_CODE="bionic-${DESKTOP}"
	DISTRO_NAME_02=ubuntu-bionic
	NODE02_ENABLED=true
	#TMOE_LINUX_CONTAINER_DISTRO="${DISTRO_NAME}-${DISTRO_CODE}"
	TMOE_LINUX_CONTAINER_DISTRO=${DISTRO_NAME_02}
	creat_container_edition_txt
	go_to_proot_management
}
set_arch_latest_env() {
	DISTRO_NAME='arch'
	DISTRO_CODE="${DESKTOP}"
	DISTRO_NAME_02=arch
	NODE02_ENABLED=true
	#TMOE_LINUX_CONTAINER_DISTRO="${DISTRO_NAME}"
	#TMOE_LINUX_CONTAINER_DISTRO="${DISTRO_NAME}-${DISTRO_CODE}"
	TMOE_LINUX_CONTAINER_DISTRO=${DISTRO_NAME_02}
	creat_container_edition_txt
	go_to_proot_management
}
set_manjaro_stable_env() {
	DISTRO_NAME='manjaro'
	DISTRO_CODE="stable-${DESKTOP}"
	DISTRO_NAME_02=manjaro-stable
	NODE02_ENABLED=true
	#TMOE_LINUX_CONTAINER_DISTRO="${DISTRO_NAME}-${DISTRO_CODE}"
	TMOE_LINUX_CONTAINER_DISTRO=${DISTRO_NAME_02}
	creat_container_edition_txt
	go_to_proot_management
}
choose_mate_distro() {
	SELECTED_GNU_LINUX=$(whiptail --title "MATE DISTROS" --menu "Which distribution do you want to install?" 0 50 0 \
		"1" "👒 Fedora-rawhide(arm64,amd64,armhf)" \
		"2" "🌉 Arch-latest(arm64,amd64)" \
		"3" "🍥 Debian-sid(arm64,amd64)" \
		"4" "🏔️ Alpine-edge(arm64,armhf,i386,amd64)" \
		"5" "Mint-tricia(amd64)" \
		"6" "🌿 Mint-ulyssa(amd64)" \
		"7" "🍛 Ubuntu-dev(amd64)" \
		"0" "🌚 Return to previous menu" \
		3>&1 1>&2 2>&3)
	case "${SELECTED_GNU_LINUX}" in
	0 | "") install_tmoe_weekly_build_edition ;;
	1)
		case ${ARCH_TYPE} in
		amd64 | arm64 | armhf) set_fedora_rawhide_env ;;
		*)
			printf "%s\n" "Sorry,tmoe-linux开发者未对当前架构（${ARCH_TYPE}）配置MATE桌面的自动构建任务。"
			distro_does_not_support
			;;
		esac
		;;
	2)
		case ${ARCH_TYPE} in
		amd64 | arm64) set_arch_latest_env ;;
		*)
			printf "%s\n" "Sorry,tmoe-linux开发者未对当前架构（${ARCH_TYPE}）配置MATE桌面的自动构建任务。"
			distro_does_not_support
			;;
		esac
		;;
	3)
		case ${ARCH_TYPE} in
		amd64 | arm64) set_debian_sid_env ;;
		*)
			printf "%s\n" "Sorry,tmoe-linux开发者未对当前架构（${ARCH_TYPE}）配置MATE桌面的自动构建任务。"
			distro_does_not_support
			;;
		esac
		;;
	4) set_alpine_edge_env ;;
	5)
		case ${ARCH_TYPE} in
		amd64) set_mint_tricia_env ;;
		*)
			printf "%s\n" "Sorry,tmoe-linux开发者未对当前架构（${ARCH_TYPE}）配置MATE桌面的自动构建任务。"
			distro_does_not_support
			;;
		esac
		;;
	6)
		case ${ARCH_TYPE} in
		amd64) set_mint_ulyssa_env ;;
		*)
			printf "%s\n" "Sorry,tmoe-linux开发者未对当前架构（${ARCH_TYPE}）配置MATE桌面的自动构建任务。"
			distro_does_not_support
			;;
		esac
		;;
	7)
		case ${ARCH_TYPE} in
		amd64) set_ubuntu_dev_env ;;
		*)
			printf "%s\n" "Sorry,tmoe-linux开发者未对当前架构（${ARCH_TYPE}）配置MATE桌面的自动构建任务。"
			distro_does_not_support
			;;
		esac
		;;
	esac
}
choose_lxde_distro() {
	SELECTED_GNU_LINUX=$(whiptail --title "LXDE DISTROS" --menu "对于LXDE桌面,开发者仅配置了i386和armhf的自动构建任务" 0 50 0 \
		"1" "🍥 Debian-sid(i386,armhf)" \
		"0" "🌚 Return to previous menu" \
		3>&1 1>&2 2>&3)
	case "${SELECTED_GNU_LINUX}" in
	0 | "") install_tmoe_weekly_build_edition ;;
	1)
		case ${ARCH_TYPE} in
		armhf | i386) set_debian_sid_env ;;
		*)
			printf "%s\n" "Sorry,tmoe-linux开发者未对当前架构（${ARCH_TYPE}）配置LXDE桌面的自动构建任务。"
			distro_does_not_support
			;;
		esac
		;;
	esac
}
choose_lxqt_distro() {
	SELECTED_GNU_LINUX=$(whiptail --title "LXQT DISTROS" --menu "Which distribution do you want to install?" 0 50 0 \
		"1" "🍛 Ubuntu-dev(arm64,amd64)" \
		"2" "👒 Fedora-rawhide(arm64,amd64)" \
		"0" "🌚 Return to previous menu" \
		3>&1 1>&2 2>&3)
	case "${SELECTED_GNU_LINUX}" in
	0 | "") install_tmoe_weekly_build_edition ;;
	1)
		case ${ARCH_TYPE} in
		amd64 | arm64) set_ubuntu_dev_env ;;
		*)
			printf "%s\n" "Sorry,tmoe-linux开发者未对当前架构（${ARCH_TYPE}）配置LXQT桌面的自动构建任务。"
			distro_does_not_support
			;;
		esac
		;;
	2)
		case ${ARCH_TYPE} in
		amd64 | arm64) set_fedora_rawhide_env ;;
		*)
			printf "%s\n" "Sorry,tmoe-linux开发者未对当前架构（${ARCH_TYPE}）配置LXQT桌面的自动构建任务。"
			distro_does_not_support
			;;
		esac
		;;
	esac
}
choose_xfce_distro() {
	SELECTED_GNU_LINUX=$(whiptail --title "XFCE DISTROS" --menu "Which distribution do you want to install?" 0 50 0 \
		"1" "🐉 Kali-rolling(arm64,armhf,amd64)" \
		"2" "🌉 Arch-latest(arm64,armhf,amd64)" \
		"3" "🍥 Debian-sid(arm64,amd64)" \
		"4" "👒 Fedora-rawhide(arm64,amd64)" \
		"5" "🍛 Ubuntu-dev(arm64,amd64)" \
		"6" "Manjaro-stable(arm64,amd64)" \
		"7" "🏔️ Alpine-edge(arm64,amd64)" \
		"0" "🌚 Return to previous menu" \
		3>&1 1>&2 2>&3)
	case "${SELECTED_GNU_LINUX}" in
	0 | "") install_tmoe_weekly_build_edition ;;
	1)
		case ${ARCH_TYPE} in
		amd64 | arm64 | armhf) set_kali_rolling_env ;;
		*)
			printf "%s\n" "Sorry,tmoe-linux开发者未对当前架构（${ARCH_TYPE}）配置XFCE桌面的自动构建任务。"
			distro_does_not_support
			;;
		esac
		;;
	2) set_arch_latest_env ;;
	3)
		case ${ARCH_TYPE} in
		amd64 | arm64) set_debian_sid_env ;;
		*)
			printf "%s\n" "Sorry,tmoe-linux开发者未对当前架构（${ARCH_TYPE}）配置XFCE桌面的自动构建任务。"
			distro_does_not_support
			;;
		esac
		;;
	4)
		case ${ARCH_TYPE} in
		amd64 | arm64) set_fedora_rawhide_env ;;
		*)
			printf "%s\n" "Sorry,tmoe-linux开发者未对当前架构（${ARCH_TYPE}）配置XFCE桌面的自动构建任务。"
			distro_does_not_support
			;;
		esac
		;;
	5)
		case ${ARCH_TYPE} in
		amd64 | arm64) set_ubuntu_dev_env ;;
		*)
			printf "%s\n" "Sorry,tmoe-linux开发者未对当前架构（${ARCH_TYPE}）配置XFCE桌面的自动构建任务。"
			distro_does_not_support
			;;
		esac
		;;
	6)
		case ${ARCH_TYPE} in
		amd64 | arm64) set_manjaro_stable_env ;;
		*)
			printf "%s\n" "Sorry,tmoe-linux开发者未对当前架构（${ARCH_TYPE}）配置XFCE桌面的自动构建任务。"
			distro_does_not_support
			;;
		esac
		;;
	7)
		case ${ARCH_TYPE} in
		amd64 | arm64) set_alpine_edge_env ;;
		*)
			printf "%s\n" "Sorry,tmoe-linux开发者未对当前架构（${ARCH_TYPE}）配置XFCE桌面的自动构建任务。"
			distro_does_not_support
			;;
		esac
		;;
	esac
}
choose_kde_distro() {
	SELECTED_GNU_LINUX=$(whiptail --title "KDE PLASMA DISTROS" --menu "If you are using proot,try using ubuntu-bionic.\nIf you are using chroot,you can choose anyone." 0 50 0 \
		"1" "🍛 Ubuntu bionic(arm64,armhf)" \
		"2" "🌉 Arch(arm64,amd64):simplicity,modernity,pragmatism" \
		"3" "🦛 Ubuntu devel(arm64,amd64)" \
		"4" "🍥 Debian sid(arm64,amd64)" \
		"5" "👒 Fedora rawhide(arm64,amd64)" \
		"6" "🏔️ Alpine(arm64,amd64):small,simple,secure." \
		"0" "🌚 Return to previous menu" \
		3>&1 1>&2 2>&3)
	case "${SELECTED_GNU_LINUX}" in
	0 | "") install_tmoe_weekly_build_edition ;;
	1)
		case ${ARCH_TYPE} in
		arm64 | armhf) set_ubuntu_bionic_env ;;
		*)
			printf "%s\n" "Sorry,tmoe-linux开发者未对当前架构（${ARCH_TYPE}）配置PLASMA桌面的自动构建任务。"
			distro_does_not_support
			;;
		esac
		;;
	2)
		case ${ARCH_TYPE} in
		amd64 | arm64) set_arch_latest_env ;;
		*)
			printf "%s\n" "Sorry,tmoe-linux开发者未对当前架构（${ARCH_TYPE}）配置XFCE桌面的自动构建任务。"
			distro_does_not_support
			;;
		esac
		;;
	3)
		case ${ARCH_TYPE} in
		amd64 | arm64) set_ubuntu_dev_env ;;
		*)
			printf "%s\n" "Sorry,tmoe-linux开发者未对当前架构（${ARCH_TYPE}）配置XFCE桌面的自动构建任务。"
			distro_does_not_support
			;;
		esac
		;;
	4)
		case ${ARCH_TYPE} in
		amd64 | arm64) set_debian_sid_env ;;
		*)
			printf "%s\n" "Sorry,tmoe-linux开发者未对当前架构（${ARCH_TYPE}）配置XFCE桌面的自动构建任务。"
			distro_does_not_support
			;;
		esac
		;;
	5)
		case ${ARCH_TYPE} in
		amd64 | arm64) set_fedora_rawhide_env ;;
		*)
			printf "%s\n" "Sorry,tmoe-linux开发者未对当前架构（${ARCH_TYPE}）配置XFCE桌面的自动构建任务。"
			distro_does_not_support
			;;
		esac
		;;
	6)
		case ${ARCH_TYPE} in
		amd64 | arm64) set_alpine_edge_env ;;
		*)
			printf "%s\n" "Sorry,tmoe-linux开发者未对当前架构（${ARCH_TYPE}）配置XFCE桌面的自动构建任务。"
			distro_does_not_support
			;;
		esac
		;;
	esac
}
choose_zsh_distro() {
	SELECTED_GNU_LINUX=$(whiptail --title "ZSH CONTAINERS" --menu "The following containers have built-in zsh" 0 50 0 \
		"1" "🌉 Arch(arm64,armhf,amd64)" \
		"2" "🦛 Ubuntu devel(arm64,amd64)" \
		"3" "🍥 Debian sid(arm64,armhf,amd64,i386)" \
		"4" "👒 Fedora rawhide(arm64,armhf,amd64)" \
		"5" "🏔️ Alpine edge(arm64,armhf,amd64,i386)" \
		"6" "🐉 Kali-rolling(arm64,armhf,amd64)" \
		"0" "🌚 Return to previous menu" \
		3>&1 1>&2 2>&3)
	case "${SELECTED_GNU_LINUX}" in
	0 | "") install_tmoe_weekly_build_edition ;;
	1)
		case ${ARCH_TYPE} in
		amd64 | armhf | arm64) set_arch_latest_env ;;
		*)
			printf "%s\n" "Sorry,tmoe-linux开发者未对当前架构（${ARCH_TYPE}）配置Zshell的自动构建任务。"
			distro_does_not_support
			;;
		esac
		;;
	2)
		case ${ARCH_TYPE} in
		amd64 | arm64) set_ubuntu_dev_env ;;
		*)
			printf "%s\n" "Sorry,tmoe-linux开发者未对当前架构（${ARCH_TYPE}）配置Zshell的自动构建任务。"
			distro_does_not_support
			;;
		esac
		;;
	3)
		case ${ARCH_TYPE} in
		amd64 | arm64 | armhf | i386) set_debian_sid_env ;;
		*)
			printf "%s\n" "Sorry,tmoe-linux开发者未对当前架构（${ARCH_TYPE}）配置Zshell的自动构建任务。"
			distro_does_not_support
			;;
		esac
		;;
	4)
		case ${ARCH_TYPE} in
		amd64 | arm64 | armhf) set_fedora_rawhide_env ;;
		*)
			printf "%s\n" "Sorry,tmoe-linux开发者未对当前架构（${ARCH_TYPE}）配置Zshell的自动构建任务。"
			distro_does_not_support
			;;
		esac
		;;
	5)
		case ${ARCH_TYPE} in
		amd64 | arm64 | armhf | i386) set_alpine_edge_env ;;
		*)
			printf "%s\n" "Sorry,tmoe-linux开发者未对当前架构（${ARCH_TYPE}）配置Zshell的自动构建任务。"
			distro_does_not_support
			;;
		esac
		;;
	6)
		case ${ARCH_TYPE} in
		amd64 | arm64 | armhf) set_kali_rolling_env ;;
		*)
			printf "%s\n" "Sorry,tmoe-linux开发者未对当前架构（${ARCH_TYPE}）配置Zshell的自动构建任务。"
			distro_does_not_support
			;;
		esac
		;;
	esac
}
##############################
#fedora-rawhide armhf xfce+lxqt -> mate
#debian-sid armhf xfce+lxde -> lxde
#alpine xfce+mate -> mate
view_the_schedule() {
	cat <<-EOF
		${BOLD}${PURPLE}Weekly builds${RESET}：
		${BOLD}${YELLOW}Tuesday/周二/火曜日${RESET}：
		TIME："UTC 00:01 / CST 08:01"
			${GREEN}ubuntu-devel ${YELLOW}arm64  ${PURPLE}*  ${BLUE}kde+xfce+lxqt+zsh${RESET}
			${GREEN}ubuntu-devel ${YELLOW}amd64  ${PURPLE}*  ${BLUE}kde+xfce+lxqt+mate+zsh${RESET}

		TIME："UTC 06:01 / CST 14:01"
			${GREEN}fedora-rawhide ${YELLOW}arm64  ${PURPLE}*  ${BLUE}kde+xfce+lxqt+mate+zsh${RESET}
			${GREEN}fedora-rawhide ${YELLOW}amd64  ${PURPLE}*  ${BLUE}kde+xfce+lxqt+mate+zsh${RESET}
			${GREEN}fedora-rawhide ${YELLOW}armhf ${PURPLE}* ${BLUE}mate+zsh${RESET}

		${BOLD}${YELLOW}Wednesday/周三/水曜日${RESET}：
		TIME："UTC 00:01 / CST 08:01"
			${GREEN}arch-latest ${YELLOW}arm64  ${PURPLE}*  ${BLUE}kde+xfce+mate+zsh${RESET}
			${GREEN}arch-latest ${YELLOW}amd64  ${PURPLE}*  ${BLUE}kde+xfce+mate+zsh${RESET}
			${GREEN}arch-latest ${YELLOW}armhf ${PURPLE}* ${BLUE}xfce+zsh${RESET}

		TIME："UTC 06:01 / CST 14:01"
			${GREEN}debian-sid ${YELLOW}arm64  ${PURPLE}*  ${BLUE}kde+xfce+mate+zsh${RESET}
			${GREEN}debian-sid ${YELLOW}amd64  ${PURPLE}*  ${BLUE}kde+xfce+mate+zsh${RESET}
			${GREEN}debian-sid ${YELLOW}armhf ${PURPLE}* ${BLUE}lxde+zsh${RESET}
			${GREEN}debian-sid ${YELLOW}i386 ${PURPLE}* ${BLUE}lxde+zsh${RESET}

		${BOLD}${YELLOW}Thursday/周四/木曜日${RESET}：
		TIME："UTC 00:01 / CST 08:01"
			${GREEN}alpine-edge ${YELLOW}arm64  ${PURPLE}*  ${BLUE}kde+xfce+mate+zsh${RESET}
			${GREEN}alpine-edge ${YELLOW}amd64  ${PURPLE}*  ${BLUE}kde+xfce+mate+zsh${RESET}
			${GREEN}alpine-edge ${YELLOW}armhf ${PURPLE}* ${BLUE}mate+zsh${RESET}
			${GREEN}alpine-edge ${YELLOW}i386 ${PURPLE}* ${BLUE}mate+zsh${RESET}

		TIME："UTC 06:01 / CST 14:01"
			${GREEN}kali-rolling ${YELLOW}arm64 ${PURPLE}* ${BLUE}xfce+zsh${RESET}
			${GREEN}kali-rolling ${YELLOW}armhf ${PURPLE}* ${BLUE}xfce+zsh${RESET}
			${GREEN}kali-rolling ${YELLOW}amd64 ${PURPLE}* ${BLUE}xfce+zsh${RESET}

		${BOLD}${PURPLE}Monthly builds${RESET}：
		${BOLD}${YELLOW}24号/24th of every month${RESET}：
		TIME："UTC 01:01 / CST 09:01"
			${GREEN}ubuntu-bionic ${YELLOW}arm64 ${PURPLE}* ${BLUE}kde${RESET}
			${GREEN}ubuntu-bionic ${YELLOW}armhf ${PURPLE}* ${BLUE}kde${RESET}
			${GREEN}linux mint-tricia ${YELLOW}amd64 ${PURPLE}* ${BLUE}mate${RESET}
			${GREEN}linux mint-ulyssa ${YELLOW}amd64 ${PURPLE}* ${BLUE}mate${RESET}
			${GREEN}manjaro-stable ${YELLOW}arm64 ${PURPLE}* ${BLUE}xfce${RESET}   
			${GREEN}manjaro-stable ${YELLOW}amd64 ${PURPLE}* ${BLUE}xfce${RESET}

	EOF
}
install_debian_gnu_linux_distro() {
	source ${TMOE_SHARE_DIR}/container/debian/menu
}
###################
install_chroot_exclusive_containers() {
	RETURN_TO_WHERE='install_chroot_exclusive_containers'
	CLOUD_ROOTFS='false'
	#\nThe developer only maintains the chroot container in the following list.
	ALPHA_SYSTEM=$(
		whiptail --title "chroot exclusive containers" --menu "虽然您仍可以使用proot运行以下容器,但开发者仅维护了chroot容器。" 0 55 0 \
			"1" "deepin深度(arm64,x86,x64)" \
			"2" "opensuse tumbleweed(小蜥蜴风滚草)" \
			"0" "🌚 Return to previous menu 返回上级菜单" \
			3>&1 1>&2 2>&3
	)
	##############################
	case "${ALPHA_SYSTEM}" in
	0 | "") choose_which_gnu_linux_distro ;;
	1) install_deepin_linux_distro ;;
	2)
		CLOUD_ROOTFS='true'
		install_opensuse_linux_distro
		;;
	esac
	###########################
	exit 0
}
###############
install_uos_eagle() {
	case "${ARCH_TYPE}" in
	amd64 | i386 | arm64) ;;
	*) distro_does_not_support ;;
	esac
	DISTRO_CODE='eagle'
	TMOE_LINUX_CONTAINER_DISTRO="${DISTRO_NAME}-${DISTRO_CODE}"
	creat_container_edition_txt
	git_clone_deepin_distro
}
###########
install_deepin_apricot_amd64_and_i386() {
	case "${ARCH_TYPE}" in
	amd64 | i386) ;;
	*) distro_does_not_support ;;
	esac
	DISTRO_CODE='apricot'
	TMOE_LINUX_CONTAINER_DISTRO="${DISTRO_NAME}-${DISTRO_CODE}"
	creat_container_edition_txt
	git_clone_deepin_distro
}
##############
install_deepin_camel_arm64() {
	case "${ARCH_TYPE}" in
	arm64) ;;
	*) distro_does_not_support ;;
	esac
	DISTRO_CODE='camel'
	TMOE_LINUX_CONTAINER_DISTRO="${DISTRO_NAME}-${DISTRO_CODE}"
	creat_container_edition_txt
	git_clone_deepin_distro
}
##########
git_clone_deepin_distro() {
	[[ -e ${ROOTFS_DIR} ]] || mkdir -pv ${ROOTFS_DIR}
	cd ${ROOTFS_DIR}
	case "${ARCH_TYPE}" in
	amd64 | i386 | arm64)
		go_to_proot_management
		DEEPIN_ROOTFS_FILE_NAME="${DISTRO_NAME}-${DISTRO_CODE}_${ARCH_TYPE}-rootfs.tar.xz"
		if [ ! -e "${DEEPIN_ROOTFS_FILE_NAME}" ]; then
			TEMP_DIR=".DEEPIN_${ARCH_TYPE}-TEMP_FOLDER"
			[[ ! -e ${TEMP_DIR} ]] || rm -rfv ${TEMP_DIR}
			git clone --depth=1 ${AK2_GIT_URL}/${DISTRO_NAME}-${DISTRO_CODE}_${ARCH_TYPE}.git ${TEMP_DIR}
			cd ${TEMP_DIR}
			cat .container_linux_* >${DEEPIN_ROOTFS_FILE_NAME}
			mv -fv ${DEEPIN_ROOTFS_FILE_NAME} ../
			cd ..
			rm -rvf ${TEMP_DIR}
		fi
		bash -c "$(sed -n p ${TMOE_SHARE_DIR}/container/install |
			sed "s/debian system/${DISTRO_NAME} system/g" |
			sed "s:debian-sid:${DISTRO_NAME}-${DISTRO_CODE}:g" |
			sed "s:Debian GNU/Linux:${DISTRO_NAME} GNU/Linux:g")"
		;;
	*) distro_does_not_support ;;
	esac
}
###############
install_deepin_linux_distro() {
	RETURN_TO_WHERE='install_deepin_linux_distro'
	ALPHA_SYSTEM=$(
		whiptail --title "DEEPIN" --menu "deepin20正式版采取统一的设计风格,从桌面环境\n和应用进行重新设计,带来焕然一新的视觉感受" 0 50 0 \
			"1" "deepin20 apricot(amd64,i386) 大小40M" \
			"2" "deepin15.5 camel(arm64) 大小78M" \
			"0" "🌚 Back 返回" \
			3>&1 1>&2 2>&3
	)
	#"999" "uos20 eagle(arm64,amd64,i386) 大小38M" \
	##############################
	case "${ALPHA_SYSTEM}" in
	0 | "") install_chroot_exclusive_containers ;;
	1)
		DISTRO_NAME='deepin'
		install_deepin_apricot_amd64_and_i386
		;;
	999)
		DISTRO_NAME='uos'
		install_uos_eagle
		;;
	2)
		DISTRO_NAME='deepin'
		install_deepin_camel_arm64
		;;
	esac
	###########################
	exit 0
}
##############
install_alpha_containers() {
	CLOUD_ROOTFS='false'
	RETURN_TO_WHERE='install_alpha_containers'
	install_alpha_containers_ja() {
		ALPHA_SYSTEM=$(
			whiptail --title "Maintenance has ceased" --menu "天萌マネージャーの開発者は、次のコンテナーを維持しなくなりました" 0 55 0 \
				"1" "OpenWRT:ゲートウェイなどの組み込みシステム用ファームウェアとして開発されている" \
				"2" "ラズベリーパイ OS buster" \
				"3" "Gentoo(arm64,armhf,x86,x64)" \
				"4" "DevuanはDebian から派生したLinuxディストリビューションである" \
				"5" "Amazon(arm64,x64)" \
				"6" "Oracle(arm64,x64)" \
				"7" "VMware photon OS(arm64,x64,optimized for cloud-native apps)" \
				"8" "Intel clear linux(x64)" \
				"9" "Slackware(armhf,x64,created by Patrick Volkerding in 1993" \
				"10" "SteamOS(x64,Valve steam os,based on Debian GNU/Linux)" \
				"0" "🌚 戻る" \
				3>&1 1>&2 2>&3
		)
	}
	install_alpha_containers_zh() {
		ALPHA_SYSTEM=$(
			whiptail --title "Maintenance has ceased" --menu "虽然您仍可以安装基础容器,但Tmoe-linux开发者已不再对以下容器进行维护" 0 55 0 \
				"1" "OpenWRT(常见于路由器等嵌入式设备)" \
				"2" "Raspberry Pi OS 樹莓派 buster" \
				"3" "Gentoo(arm64,armhf,x86,x64,追求极限配置和极高自由)" \
				"4" "Devuan(不使用systemd,基于debian)" \
				"5" "Amazon(arm64,x64,亚马逊云服务器系统)" \
				"6" "Oracle(arm64,x64,甲骨文云服务器系统)" \
				"7" "VMware photon OS(arm64,x64,optimized for cloud-native apps)" \
				"8" "Intel clear linux(x64,专注于服务器的性能优化,应用于云环境)" \
				"9" "Slackware(armhf,x64,created by Patrick Volkerding in 1993" \
				"10" "SteamOS(x64,蒸汽平台开发商Valve发行的游戏系统,基于debian)" \
				"0" "🌚 返回上级菜单" \
				3>&1 1>&2 2>&3
		)
		#"5" "Huawei euler OS(arm64,x64,华为欧拉,服务器系统)" \
	}
	install_alpha_containers_en() {
		ALPHA_SYSTEM=$(
			whiptail --title "Maintenance has ceased" --menu "The developer of Tmoe-linux no longer maintain the following containers." 0 55 0 \
				"1" "OpenWRT is a Linux OS targeting embedded devices" \
				"2" "Raspberry Pi OS buster" \
				"3" "Gentoo(arm64,armhf,x86,x64)" \
				"4" "Devuan is a fork of Debian that uses sysvinit or OpenRC instead of systemd" \
				"5" "Amazon(arm64,x64)" \
				"6" "Oracle(arm64,x64)" \
				"7" "VMware photon OS(arm64,x64,optimized for cloud-native apps)" \
				"8" "Intel clear linux(x64)" \
				"9" "Slackware(armhf,x64,created by Patrick Volkerding in 1993" \
				"10" "SteamOS(x64,Valve steam os,based on Debian GNU/Linux)" \
				"0" "🌚 Return to previous menu" \
				3>&1 1>&2 2>&3
		)
	}
	#"999" "Huawei euler OS(arm64,x64)"
	#SteamOS(x64,Valve steam os,based on Debian GNU/Linux)
	#"99" "Microsoft CBL-Mariner(x64,为azure优化,用于微软的云基础设施和边缘产品和服务)" \
	#				"12" "Solus(x64)" \
	##############################
	case ${TMOE_MENU_LANG} in
	zh_*UTF-8) install_alpha_containers_zh ;;
	ja_JP.UTF-8) install_alpha_containers_ja ;;
	*) install_alpha_containers_en ;;
	esac
	case "${ALPHA_SYSTEM}" in
	0 | "") choose_which_gnu_linux_distro ;;
	1) install_openwrt_linux_distro ;;
	2) install_raspios_linux_distro ;;
	3) install_gentoo_linux_distro ;;
	4) install_devuan_linux_distro ;;
	5) install_amazon_linux_distro ;;
	6) install_oracle_linux_distro ;;
	7) install_photon_linux_distro ;;
	8) install_clear_linux_distro ;;
	9) install_slackware_linux_distro ;;
	10) install_steam_linux_distro ;;
	999) install_euler_linux_distro ;;
	esac
	###########################
	exit 0
}
#########################
install_clear_linux_distro() {
	DISTRO_NAME='clear'
	TMOE_LINUX_CONTAINER_DISTRO='clear'
	case "${ARCH_TYPE}" in
	'amd64')
		creat_container_edition_txt
		go_to_proot_management
		git_clone_linux_distro_rootfs_01
		;;
	*) distro_does_not_support ;;
	esac
}
install_steam_linux_distro() {
	DISTRO_NAME='steamos'
	DISTRO_CODE='brewmaster'
	TMOE_LINUX_CONTAINER_DISTRO="${DISTRO_NAME}-${DISTRO_CODE}"
	case "${ARCH_TYPE}" in
	'amd64')
		creat_container_edition_txt
		go_to_proot_management
		git_clone_linux_distro_rootfs_01
		;;
	*) distro_does_not_support ;;
	esac
}
install_puppy_linux_distro() {
	DISTRO_NAME='puppy'
	DISTRO_CODE='fossa'
	TMOE_LINUX_CONTAINER_DISTRO="${DISTRO_NAME}-${DISTRO_CODE}"
	case "${ARCH_TYPE}" in
	'amd64')
		creat_container_edition_txt
		go_to_proot_management
		git_clone_linux_distro_rootfs_01
		;;
	*) distro_does_not_support ;;
	esac
}
install_euler_linux_distro() {
	DISTRO_NAME='euler'
	TMOE_LINUX_CONTAINER_DISTRO='euler'
	case "${ARCH_TYPE}" in
	'amd64' | 'arm64')
		creat_container_edition_txt
		go_to_proot_management
		git_clone_linux_distro_rootfs_01
		;;
	*) distro_does_not_support ;;
	esac
}
install_photon_linux_distro() {
	DISTRO_NAME='photon'
	TMOE_LINUX_CONTAINER_DISTRO='photon'
	case "${ARCH_TYPE}" in
	'amd64' | 'arm64')
		creat_container_edition_txt
		go_to_proot_management
		git_clone_linux_distro_rootfs_01
		;;
	*) distro_does_not_support ;;
	esac
}
install_amazon_linux_distro() {
	DISTRO_NAME='amazon'
	DISTRO_CODE='2'
	TMOE_LINUX_CONTAINER_DISTRO="${DISTRO_NAME}-${DISTRO_CODE}"
	case "${ARCH_TYPE}" in
	'amd64' | 'arm64')
		creat_container_edition_txt
		go_to_proot_management
		git_clone_linux_distro_rootfs_01
		;;
	*) distro_does_not_support ;;
	esac
}
install_oracle_linux_distro() {
	DISTRO_NAME='oracle'
	DISTRO_CODE=8
	TMOE_LINUX_CONTAINER_DISTRO="${DISTRO_NAME}-${DISTRO_CODE}"
	case "${ARCH_TYPE}" in
	'arm64')
		creat_container_edition_txt
		go_to_proot_management
		git_clone_linux_distro_rootfs_01
		;;
	amd64)
		CLOUD_ROOTFS=true
		DISTRO_CODE=$(curl -L https://mirrors.bfsu.edu.cn/lxc-images/images/oracle/ | grep date | sed -E 's@<a (href)@\n\1@g' | awk -F 'href=' '{print $2}' | cut -d '"' -f 2 | tail -n 1 | cut -d '/' -f 1)
		TMOE_LINUX_CONTAINER_DISTRO="${DISTRO_NAME}-${DISTRO_CODE}"
		creat_container_edition_txt
		go_to_proot_management
		linux_distro_common_model_04
		;;
	*) distro_does_not_support ;;
	esac
}
####################
git_clone_linux_distro_rootfs_01() {
	mkdir -pv ${ROOTFS_DIR}
	cd ${ROOTFS_DIR}
	ROOTFS_FILE_NAME="${TMOE_LINUX_CONTAINER_DISTRO}_${ARCH_TYPE}-rootfs.tar.xz"
	if [ ! -e "${ROOTFS_FILE_NAME}" ]; then
		TEMP_DIR=".${TMOE_LINUX_CONTAINER_DISTRO}-TEMP_FOLDER"
		[[ ! -e ${TEMP_DIR} ]] || rm -rfv ${TEMP_DIR}
		pwd
		git clone --depth=1 ${AK2_GIT_URL}/${TMOE_LINUX_CONTAINER_DISTRO}_${ARCH_TYPE}.git ${TEMP_DIR}
		cd ${TEMP_DIR}
		cat .container_linux_* >${ROOTFS_FILE_NAME}
		mv -fv ${ROOTFS_FILE_NAME} ../
		cd ..
		rm -rvf ${TEMP_DIR}
	fi
	bash -c "$(sed -n p ${TMOE_SHARE_DIR}/container/install |
		sed "s/debian system/${DISTRO_NAME} system/g" |
		sed "s:debian-sid:${TMOE_LINUX_CONTAINER_DISTRO}:g" |
		sed "s:Debian GNU/Linux:${DISTRO_NAME} GNU/Linux:g")"
}
#######################
install_beta_containers() {
	CLOUD_ROOTFS='false'
	install_beta_containers_zh() {
		BETA_SYSTEM=$(
			whiptail --title "Beta features" --menu "公测版容器将带给您别样的惊喜\nBeta container, endless fun." 0 55 0 \
				"1" "Manjaro(arm64,x64,让arch更方便用户使用)" \
				"2" "🏔️ Alpine(基于musl libc和busybox,超精简系统)" \
				"3" "CentOS(基于红帽的社区企业操作系统)" \
				"4" "🐶 Puppy(x64,小巧且易用,速度快)" \
				"5" "Void(基于xbps包管理器的独立发行版)" \
				"6" "🌿 Mint(x86,x64,简单易用的系统)" \
				"0" "🌚 Return to previous menu 返回上级菜单" \
				3>&1 1>&2 2>&3
		)
	}
	install_beta_containers_ja() {
		BETA_SYSTEM=$(
			whiptail --title "Beta features" --menu "Beta container, endless fun." 0 55 0 \
				"1" "Manjaro:Archをベースとした、ユーザーフレンドリーなディストリビューションを目指している" \
				"2" "🏔️ Alpine:セキュリティ・シンプルさ・リソース効率を重視するパワーユーザー向けに設計されている" \
				"3" "CentOS:RHELと機能的に互換性があることを目指したフリーのLinuxディストリビューションである" \
				"4" "🐶 Puppy(x64,extremely low minimum system requirements)" \
				"5" "Void:ゼロから設計および実装されたX Binary Package System" \
				"6" "🌿 Mint(x86,x64,洗練され、最新で快適なLinuxデスクトップを提供すること)" \
				"0" "🌚 戻る" \
				3>&1 1>&2 2>&3
		)
	}
	install_beta_containers_en() {
		BETA_SYSTEM=$(
			whiptail --title "Beta features" --menu "Beta container, endless fun." 0 55 0 \
				"1" "Manjaro:Free fast and secure Linux based operating system for everyone" \
				"2" "🏔️ Alpine:Small. Simple. Secure. Alpine Linux is a security-oriented, lightweight Linux distribution based on musl libc and busybox" \
				"3" "CentOS is a community-driven free software effort focused on delivering a robust open source ecosystem around a Linux platform" \
				"4" "🐶 Puppy(x64,extremely low minimum system requirements)" \
				"5" "Void is a general purpose operating system, based on the monolithic Linux kernel" \
				"6" "🌿 Mint(x86,x64,elegant, easy to use, up to date and comfortable GNU/Linux desktop distribution)" \
				"0" "🌚 Return to previous menu" \
				3>&1 1>&2 2>&3
		)
	}
	##############################
	case ${TMOE_MENU_LANG} in
	zh_*UTF-8) install_beta_containers_zh ;;
	ja_JP.UTF-8) install_beta_containers_ja ;;
	*) install_beta_containers_en ;;
	esac

	case "${BETA_SYSTEM}" in
	0 | "") choose_which_gnu_linux_distro ;;
	1)
		DISTRO_NAME='manjaro'
		TMOE_LINUX_CONTAINER_DISTRO='manjaro'
		creat_container_edition_txt
		go_to_proot_management
		install_manjaro_linux_distro
		;;
	2)
		TMOE_LINUX_CONTAINER_DISTRO='alpine'
		install_alpine_linux_distro
		;;
	3)
		CLOUD_ROOTFS='true'
		install_centos_linux_distro
		;;
	4) install_puppy_linux_distro ;;
	5)
		TMOE_LINUX_CONTAINER_DISTRO='void'
		creat_container_edition_txt
		install_void_linux_distro
		;;
	6) install_mint_linux_distro ;;
	esac
	######################
	exit 0
}
#####################
install_ubuntu_gnu_linux_distro() {
	DISTRO_NAME='ubuntu'
	DISTRO_CODE='focal'
	DEB_BOOT_STRAP='false'
	RETURN_TO_WHERE='install_ubuntu_gnu_linux_distro'
	COMPATIBILITY_MODE='false'
	install_ubuntu_gnu_linux_distro_zh() {
		BETA_SYSTEM=$(
			whiptail --title "Which version do you want to install?" --menu "2020至2025年的长期支持版为focal 20.04(2020年4月正式发布)\n设x=当前年份,若x>=2022,则请手动输入版本代号" 0 50 0 \
				"1" "🦍 20.10 Groovy Gorilla 時髦大猩猩" \
				"2" "🐱 20.04(LTS)Focal Fossa 焦點馬島長尾狸貓" \
				"3" "18.04(LTS)Bionic Beaver 仿生海狸" \
				"4" "Compatibility mode 兼容模式(仅安装)" \
				"5" "Custom code手动输入版本代号" \
				"6" "使用debootstrap手动构建" \
				"7" "🦛 21.04 Hirsute Hippo 多毛河馬" \
				"8" "Latest(自動檢測21.10)" \
				"0" "🌚 Return to previous menu 返回上级菜单" \
				3>&1 1>&2 2>&3
		)
	}
	#	"8" "🐿️ 16.04(LTS)Xenial Xerus 好客的非洲地松鼠" \
	install_ubuntu_gnu_linux_distro_ja() {
		BETA_SYSTEM=$(
			whiptail --title "Which version do you want to install?" --menu "x =現在の年とします、x> = 2022の場合は、コードをカスタマイズしてください" 0 50 0 \
				"1" "🦍 20.10 Groovy Gorilla" \
				"2" "🐱 20.04(LTS)Focal Fossa注目を集めるフォッサ" \
				"3" "18.04(LTS)Bionic Beaver" \
				"4" "互換モード" \
				"5" "カスタムコード" \
				"6" "debootstrapを使用して手動でビルドする" \
				"7" "🦛 21.04 Hirsute Hippo" \
				"8" "Latest(最新バージョンを自動的に検出)" \
				"0" "🌚 戻る" \
				3>&1 1>&2 2>&3
		)
	}
	install_ubuntu_gnu_linux_distro_en() {
		BETA_SYSTEM=$(
			whiptail --title "Which version do you want to install?" --menu "The long-term support version from 2020 to 2025 is focal(20.04).\nLet x = current year, if x>=2022,then customize the version code" 0 50 0 \
				"1" "🦍 20.10 Groovy Gorilla" \
				"2" "🐱 20.04(LTS)Focal Fossa" \
				"3" "18.04(LTS)Bionic Beaver" \
				"4" "Compatibility mode" \
				"5" "Custom code" \
				"6" "Manually build using debootstrap" \
				"7" "🦛 21.04 Hirsute Hippo" \
				"8" "Latest" \
				"0" "🌚 Return to previous menu" \
				3>&1 1>&2 2>&3
		)
	}
	#🦦
	case ${TMOE_MENU_LANG} in
	zh_*UTF-8) install_ubuntu_gnu_linux_distro_zh ;;
	ja_JP.UTF-8) install_ubuntu_gnu_linux_distro_ja ;;
	*) install_ubuntu_gnu_linux_distro_en ;;
	esac
	##############################
	case "${BETA_SYSTEM}" in
	0 | "") choose_which_gnu_linux_distro ;;
	1) DISTRO_CODE='groovy' ;;
	2) DISTRO_CODE='focal' ;;
	3) DISTRO_CODE='bionic' ;;
	4)
		COMPATIBILITY_MODE='true'
		custom_ubuntu_version
		;;
	5) custom_ubuntu_version ;;
	6) debootstrap_ubuntu_distro ;;
	7) DISTRO_CODE='hirsute' ;;
	8) check_the_latest_ubuntu_version ;;
	esac
	######################
	TMOE_LINUX_CONTAINER_DISTRO="${DISTRO_NAME}-${DISTRO_CODE}"
	creat_container_edition_txt
	go_to_proot_management
	####################
	exit 0
}
#########################
check_ubuntu_distro_code() {
	case ${DISTRO_CODE} in
	bionic | xenial | eoan) ;;
	*)
		case "${ARCH_TYPE}" in
		"i386")
			printf "%s\n" "已不再提供${DISTRO_CODE}的i386镜像,将为您降级到18.04-bionic"
			DISTRO_CODE='bionic'
			;;
		esac
		;;
	esac
	printf "%s\n" "即将为您安装Ubuntu ${DISTRO_CODE} GNU/Linux container"
	do_you_want_to_continue
	install_different_ubuntu_gnu_linux_distros
}
##############
custom_ubuntu_version() {
	#12 50
	TARGET=$(whiptail --inputbox "请输入ubuntu版本代号，例如focal(英文小写)\nPlease type the ubuntu version code." 9 50 --title "UBUNTU CODE" 3>&1 1>&2 2>&3)
	#[[ "$?" = 0 ]] || ${RETURN_TO_WHERE} #此處不要判斷退出狀態
	DISTRO_CODE="$(printf '%s\n' "${TARGET}" | head -n 1 | cut -d ' ' -f 1)"
	if [ -z "${DISTRO_CODE}" ]; then
		printf "%s\n" "检测到您取消了操作"
		printf "%s\n" "已自动切换为ubuntu20.04(代号focal)"
		DISTRO_CODE='focal'
	fi
}
#################
debootstrap_ubuntu_distro() {
	case ${TMOE_CHROOT} in
	true) ;;
	*)
		if [[ ${LINUX_DISTRO} = 'Android' ]]; then
			printf "%s\n" "Sorry,暂不支持您的系统。"
			printf "%s\n" "请换用chroot容器。"
			press_enter_to_return
			install_ubuntu_gnu_linux_distro
		fi
		;;
	esac
	[[ $(command -v debootstrap) ]] || ${TMOE_INSTALLATION_COMMAND} debootstrap
	custom_ubuntu_version
	printf "%s\n" "${DISTRO_CODE}"
	do_you_want_to_continue
	TMOE_LINUX_CONTAINER_DISTRO="${DISTRO_NAME}-${DISTRO_CODE}"
	#此处重复创建并非多余
	creat_container_edition_txt
	if [ ! -e "${DEBIAN_CHROOT}" ]; then
		DEB_BOOT_STRAP='true'
		printf "%s\n" "${DEBIAN_CHROOT}"
		link_debootstrap_script
		if (whiptail --title "UBUNTU URL" --yes-button "BFSU MIRROR" --no-button "UBUNTU OFFICIAL" --yesno "Which url do you want to choose?" 8 50); then
			case ${ARCH_TYPE} in
			amd64 | i386) UBUNTU_MIRROR_URL="http://mirrors.bfsu.edu.cn/ubuntu" ;;
			*) UBUNTU_MIRROR_URL="http://mirrors.bfsu.edu.cn/ubuntu-ports" ;;
			esac
		else
			case ${ARCH_TYPE} in
			amd64 | i386) UBUNTU_MIRROR_URL="http://archive.ubuntu.com/ubuntu" ;;
			*) UBUNTU_MIRROR_URL="http://ports.ubuntu.com/ubuntu-ports" ;;
			esac
		fi
		${TMOE_PREFIX} mkdir -pv ${DEBIAN_CHROOT}
		#--include=apt-utils,curl,ca-certificates,locales,locales-all,whiptail,apt-transport-https
		${TMOE_PREFIX} debootstrap --no-check-gpg --arch ${ARCH_TYPE} --components=main,restricted,universe,multiverse --variant=minbase --include=init,locales,ca-certificates,openssl ${DISTRO_CODE} ${DEBIAN_CHROOT} ${UBUNTU_MIRROR_URL}
		if [[ ${DEBIAN_CHROOT} != / && -n ${DEBIAN_CHROOT} ]]; then
			${TMOE_PREFIX} rm -fv ${DEBIAN_CHROOT}/dev/*
		fi
		printf "%s\n" "DEBOOTSTRAP_DIR=${DEBIAN_CHROOT}" >${CONFIG_FOLDER}/debootstrap_dir.txt
	fi
	#debootstrap --no-check-gpg --arch arm64 --include=gawk,libblkid1,libbz2-1.0,libc6,libcom-err2,libcrypt1,libdebconfclient0,libext2fs2,libgcc-s1,libgmp10,liblzma5,libnss-nis,libnss-nisplus,libpam-modules-bin,libpam0g,libpcre3,libselinux1,libss2,libtinfo6,libuuid1,tar,zlib1g --variant=minbase sid ./sid ${UBUNTU_MIRROR_URL}
	#
}
#############
ubuntu_distro_x64_model() {
	bash -c "$(sed -n p ${TMOE_SHARE_DIR}/container/install |
		sed "s/focal/${DISTRO_CODE}/g" |
		sed 's@ARCH_TYPE\}/default@ARCH_TYPE\}/cloud@' |
		sed "s/debian system/${DISTRO_NAME} system/g" |
		sed "s:debian-sid:${DISTRO_NAME}-${DISTRO_CODE}:g" |
		sed "s:debian/sid:${DISTRO_NAME}/${DISTRO_CODE}:g" |
		sed "s:/${DISTRO_NAME}-ports:/${DISTRO_NAME}:g" |
		sed "s:Debian GNU/Linux:${DISTRO_NAME} GNU/Linux:g")"
}
############
ubuntu_distro_arm_model() {
	bash -c "$(sed -n p ${TMOE_SHARE_DIR}/container/install |
		sed "s/focal/${DISTRO_CODE}/g" |
		sed 's@ARCH_TYPE\}/default@ARCH_TYPE\}/cloud@' |
		sed "s/debian system/${DISTRO_NAME} system/g" |
		sed "s:debian-sid:${DISTRO_NAME}-${DISTRO_CODE}:g" |
		sed "s:debian/sid:${DISTRO_NAME}/${DISTRO_CODE}:g" |
		sed "s:Debian GNU/Linux:${DISTRO_NAME} GNU/Linux:g")"
}
########
ubuntu_distro_x64_model_02() {
	bash -c "$(sed -n p ${TMOE_SHARE_DIR}/container/install |
		sed "s/focal/${DISTRO_CODE}/g" |
		sed 's@ARCH_TYPE\}/default@ARCH_TYPE\}/cloud@' |
		sed "s/debian system/${DISTRO_NAME} system/g" |
		sed "s:debian-sid:${DISTRO_NAME}-${DISTRO_CODE}:g" |
		sed "s:debian/sid:${DISTRO_NAME}/${DISTRO_CODE}:g" |
		sed "s:/${DISTRO_NAME}-ports:/${DISTRO_NAME}:g" |
		sed "/usermod -a/d" |
		sed "/groupadd /d" |
		sed "s:Debian GNU/Linux:${DISTRO_NAME} GNU/Linux:g")"
}
############
ubuntu_distro_arm_model_02() {
	bash -c "$(sed -n p ${TMOE_SHARE_DIR}/container/install |
		sed "s/focal/${DISTRO_CODE}/g" |
		sed 's@ARCH_TYPE\}/default@ARCH_TYPE\}/cloud@' |
		sed "s/debian system/${DISTRO_NAME} system/g" |
		sed "s:debian-sid:${DISTRO_NAME}-${DISTRO_CODE}:g" |
		sed "s:debian/sid:${DISTRO_NAME}/${DISTRO_CODE}:g" |
		sed "s:Debian GNU/Linux:${DISTRO_NAME} GNU/Linux:g")"
}
########
linux_distro_common_model_01() {
	bash -c "$(sed -n p ${TMOE_SHARE_DIR}/container/install |
		sed "s/debian system/${DISTRO_NAME} system/g" |
		sed "s:debian-sid:${DISTRO_NAME}-${DISTRO_CODE}:g" |
		sed "s:debian/sid:${DISTRO_NAME}/${DISTRO_CODE}:g" |
		sed "/usermod -a/d" |
		sed "/groupadd /d" |
		sed "s:Debian GNU/Linux:${DISTRO_NAME} GNU/Linux:g")"
}
####################
#02为kali-rolling
linux_distro_common_model_02() {
	bash -c "$(sed -n p ${TMOE_SHARE_DIR}/container/install |
		sed "s/debian system/${DISTRO_NAME} system/g" |
		sed 's@ARCH_TYPE\}/default@ARCH_TYPE\}/cloud@' |
		sed "s:debian-sid:${DISTRO_NAME}-${DISTRO_CODE}:g" |
		sed "s:debian/sid:${DISTRO_NAME}/${DISTRO_CODE_02}:g" |
		sed "s:Debian GNU/Linux:${DISTRO_NAME} GNU/Linux:g")"
}
#########################
#03为arch linux
#############
#04为fedora和centos
linux_distro_common_model_04() {
	bash -c "$(sed -n p ${TMOE_SHARE_DIR}/container/install |
		sed "s/debian system/${DISTRO_NAME} system/g" |
		sed 's@ARCH_TYPE\}/default@ARCH_TYPE\}/cloud@' |
		sed "s:debian-sid:${DISTRO_NAME}-${DISTRO_CODE}:g" |
		sed "s:debian/sid:${DISTRO_NAME}/${DISTRO_CODE}:g" |
		sed "s:Debian GNU/Linux:${DISTRO_NAME} GNU/Linux:g")"
}
####################
install_different_ubuntu_gnu_linux_distros() {
	case ${COMPATIBILITY_MODE} in
	true)
		case "${ARCH_TYPE}" in
		amd64 | i386) ubuntu_distro_x64_model_02 ;;
		*) ubuntu_distro_arm_model_02 ;;
		esac
		;;
	*)
		case "${ARCH_TYPE}" in
		amd64 | i386) ubuntu_distro_x64_model ;;
		*) ubuntu_distro_arm_model ;;
		esac
		;;
	esac
	#UBUNTU ppc64el/s390x/arm架构需使用ports源
}
############
check_the_latest_ubuntu_version() {
	LXC_IMAGES_REPO="https://mirrors.bfsu.edu.cn/lxc-images/images/${DISTRO_NAME}/"
	DISTRO_CODE=$(curl -L ${LXC_IMAGES_REPO} | grep date | cut -d '=' -f 4 | cut -d '"' -f 2 | egrep -v 'size|bionic|cosmic|disco|eoan|focal|trusty|xenial|groovy|hirsute' | tail -n 1)
	if [ -z ${DISTRO_CODE} ]; then
		printf "%s\n" "未检测到最新版本，将自动获取ubuntu 21.04 hirsute"
		DISTRO_CODE='hirsute'
		do_you_want_to_continue
	fi
}
##########
install_kali_rolling_gnu_linux_distro() {
	DISTRO_NAME='kali'
	DISTRO_CODE='rolling'
	DISTRO_CODE_02='current'
	linux_distro_common_model_02
}
#####################
install_arch_linux_distro() {
	DISTRO_NAME='archlinux'
	DISTRO_CODE='latest'
	DISTRO_CODE_02='current'
	case ${ARCH_TYPE} in
	armhf)
		bash -c "$(sed -n p ${TMOE_SHARE_DIR}/container/install |
			sed 's@${TUNA_LXC_IMAGE_MIRROR_REPO}.*rootfs.tar.xz@https://mirrors.bfsu.edu.cn/archlinuxarm/os/ArchLinuxARM-armv7-latest.tar.gz@g' |
			sed "s/debian system/${DISTRO_NAME} system/g" |
			sed "s:debian-sid:${DISTRO_NAME}-${DISTRO_CODE}:g" |
			sed 's:rootfs.tar.xz:rootfs.tar.gz:g' |
			sed "s:Debian GNU/Linux:${DISTRO_NAME}:g")"
		;;
	amd64 | arm64) linux_distro_common_model_03 ;;
	*) distro_does_not_support ;;
	esac
}
############
check_the_latest_distro_version() {
	LXC_IMAGES_REPO="https://mirrors.bfsu.edu.cn/lxc-images/images/${DISTRO_NAME}/"
	DISTRO_CODE=$(curl -sL ${LXC_IMAGES_REPO} | grep date | tail -n 1 | cut -d '=' -f 4 | cut -d '"' -f 2)
	which_version_do_you_want_to_install
}
#################
case_cloud_rootfs_01_04() {
	case ${CLOUD_ROOTFS} in
	true) linux_distro_common_model_04 ;;
	*) linux_distro_common_model_01 ;;
	esac
}
###########
before_going_to_proot_menu() {
	TMOE_LINUX_CONTAINER_DISTRO="${DISTRO_NAME}-${DISTRO_CODE}"
	creat_container_edition_txt
	go_to_proot_management
}
which_version_do_you_want_to_install() {
	if (whiptail --title "${DISTRO_NAME} VERSION" --yes-button "${DISTRO_CODE}" --no-button "${OLD_STABLE_VERSION}" --yesno "您想要安装哪个版本？Which version do you want to install?检测到当前的最新版本(latest version)为${DISTRO_CODE}" 9 50); then
		before_going_to_proot_menu
		case_cloud_rootfs_01_04
	else
		DISTRO_CODE="${OLD_STABLE_VERSION}"
		before_going_to_proot_menu
		case_cloud_rootfs_01_04
	fi
}
######################
fedora_distro_menu() {
	RETURN_TO_WHERE='fedora_distro_menu'
	BETA_SYSTEM=$(
		whiptail --title "Fedora" --menu "您想要安装哪个Fedora版本？\nWhich version do you want to install?" 0 0 0 \
			"1" "Auto check 自动检测版本" \
			"2" "35 rawhide(For testing only)" \
			"0" "🌚 Return to previous menu 返回上级菜单" \
			3>&1 1>&2 2>&3
		#			"2" "34" \
	)
	##############################
	case "${BETA_SYSTEM}" in
	0 | "") choose_which_gnu_linux_distro ;;
	1)
		OLD_STABLE_VERSION=$(curl -L https://mirrors.bfsu.edu.cn/lxc-images/images/fedora/ | grep date | tail -n 2 | head -n 1 | cut -d '=' -f 4 | cut -d '"' -f 2)
		check_the_latest_distro_version
		;;
		#2)
		#	DISTRO_CODE=34
		#case ${ARCH_TYPE} in
		#amd64) CORRENT_SHA256SUM='4f8471bb8402d8b903fbe0a4944df5f935a6b32b0a3032e645ac6881a60ef4dc' ;;
		#arm64) CORRENT_SHA256SUM='504be6ae28e26f3d94166e480fc8b59f1c7e469df0d7de510056c951f9ce50d5' ;;
		#esac
		#	git_clone_fedora_rootfs
	#	;;
	2)
		DISTRO_CODE=35
		git_clone_fedora_rootfs
		;;
	esac
	######################
	press_enter_to_return
	tmoe_manager_main_menu
}
#########################
git_clone_fedora_rootfs() {
	TMOE_LINUX_CONTAINER_DISTRO="${DISTRO_NAME}-${DISTRO_CODE}"
	creat_container_edition_txt
	go_to_proot_management
	[[ -e ${ROOTFS_DIR} ]] || mkdir -pv ${ROOTFS_DIR}
	cd ${ROOTFS_DIR}
	FEDORA_ROOTFS_FILE="fedora-${DISTRO_CODE}_${ARCH_TYPE}-rootfs.tar.xz"
	FEDORA_TEMP_FOLDER=".${FEDORA_ROOTFS_FILE}_TEMP_FOLDER"
	if [[ ! -s "${FEDORA_ROOTFS_FILE}" ]]; then
		rm -rv ${FEDORA_TEMP_FOLDER} 2>/dev/null
		git clone --depth=1 ${AK2_GIT_URL}/fedora-${DISTRO_CODE}_${ARCH_TYPE} ${FEDORA_TEMP_FOLDER}
		mv -f ${FEDORA_TEMP_FOLDER}/fedora-${DISTRO_CODE}_${ARCH_TYPE}.tar.xz ${ROOTFS_DIR}/${FEDORA_ROOTFS_FILE}
		rm -rvf ${FEDORA_TEMP_FOLDER}
	fi
	case ${DISTRO_CODE} in
	33)
		bash -c "$(sed -n p ${TMOE_SHARE_DIR}/container/install |
			sed "s/debian system/${DISTRO_NAME} system/g" |
			sed "s:debian-sid:${DISTRO_NAME}-${DISTRO_CODE}:g" |
			sed "s:debian/sid:${DISTRO_NAME}/${DISTRO_CODE}:g" |
			sed "s:Debian GNU/Linux:${DISTRO_NAME} GNU/Linux:g")"
		;;
	*)
		bash -c "$(sed -n p ${TMOE_SHARE_DIR}/container/install |
			sed "s/debian system/${DISTRO_NAME} system/g" |
			sed "s:debian-sid:${DISTRO_NAME}-${DISTRO_CODE}:g" |
			sed "s:debian/sid:${DISTRO_NAME}/${DISTRO_CODE}:g" |
			sed "s@\(FEDORA_VERSION=\).*@\129@g" |
			sed "s:Debian GNU/Linux:${DISTRO_NAME} GNU/Linux:g")"
		#当版本低于30，或为rawhide时不会自动换源
		;;
	esac
}
###################
install_fedora_gnu_linux_distro() {
	#touch ~/.REDHATDetectionFILE
	DISTRO_NAME='fedora'
	TMOE_LINUX_CONTAINER_DISTRO='fedora'
	CLOUD_ROOTFS='true'
	case "${ARCH_TYPE}" in
	armel | i386) distro_does_not_support ;;
	armhf)
		DISTRO_CODE=33
		TMOE_LINUX_CONTAINER_DISTRO="${DISTRO_NAME}-${DISTRO_CODE}"
		creat_container_edition_txt
		go_to_proot_management
		[[ -e ${ROOTFS_DIR} ]] || mkdir -pv ${ROOTFS_DIR}
		cd ${ROOTFS_DIR}
		FEDORA_ROOTFS_FILE='fedora-33_armhf-rootfs.tar.xz'
		FEDORA_TEMP_FOLDER=".${FEDORA_ROOTFS_FILE}_TEMP_FOLDER"
		if [[ ! -s "${FEDORA_ROOTFS_FILE}" ]]; then
			rm -rv ${FEDORA_TEMP_FOLDER} 2>/dev/null
			git clone --depth=1 ${AK2_GIT_URL}/fedora-33_armhf ${FEDORA_TEMP_FOLDER}
			mv -f ${FEDORA_TEMP_FOLDER}/${FEDORA_ROOTFS_FILE} ${ROOTFS_DIR}
			rm -rvf ${FEDORA_TEMP_FOLDER}
		fi
		: <<\EOF
		#CORRENT_SHA256SUM='bec3047102e6edbb834735233713f45ef085f9b8e46f493f39732f53891d3a0e'
		printf "%s\n" 'Verifying sha256hash...'
		printf "%s\n" '正在校验sha256哈希值...'
		printf "%s\n" "${CORRENT_SHA256SUM}"
		LOCAL_SHA256SUM=$(sha256sum ${FEDORA_ROOTFS_FILE} | cut -c 1-64)
		case ${LOCAL_SHA256SUM} in
		"${CORRENT_SHA256SUM}") printf "%s\n" "Congratulations！检测到sha256哈希值与源文件一致。" ;;
		esac
EOF
		linux_distro_common_model_01
		;;
	*)
		#OLD_STABLE_VERSION='31'
		fedora_distro_menu
		;;
	esac
}
#######################
linux_distro_common_model_03() {
	bash -c "$(sed -n p ${TMOE_SHARE_DIR}/container/install |
		sed "s/debian system/${DISTRO_NAME} system/g" |
		sed "s:debian-sid:${DISTRO_NAME}-${DISTRO_CODE}:g" |
		sed "s:debian/sid:${DISTRO_NAME}/${DISTRO_CODE_02}:g" |
		sed "s:Debian GNU/Linux:${DISTRO_NAME}:g")"
}
#################
install_void_linux_distro() {
	DISTRO_NAME='voidlinux'
	DISTRO_CODE='default'
	DISTRO_CODE_02='current'
	linux_distro_common_model_03
}
##########################
install_centos_linux_distro() {
	#touch ~/.REDHATDetectionFILE
	DISTRO_NAME='centos'
	case "${ARCH_TYPE}" in
	"armhf" | "i386")
		printf "%s\n" "检测到CentOS 8不支持您当前的架构，将为您降级至CentOS 7"
		DISTRO_CODE='7'
		TMOE_LINUX_CONTAINER_DISTRO="${DISTRO_NAME}-${DISTRO_CODE}"
		creat_container_edition_txt
		go_to_proot_management
		linux_distro_common_model_04
		;;
	*)
		OLD_STABLE_VERSION='8'
		check_the_latest_distro_version
		#DISTRO_CODE='8'
		#linux_distro_common_model_01
		;;
	esac
}
######################
install_gentoo_linux_distro() {
	DISTRO_NAME='gentoo'
	TMOE_LINUX_CONTAINER_DISTRO='gentoo'
	case "${ARCH_TYPE}" in
	'arm64')
		#printf "%s\n" "检测到您当前使用的是arm64架构，将临时识别为armhf"
		#NEW_TMOE_ARCH='armhf'
		#TMOE_QEMU_ARCH=""
		#ARCH_TYPE='armhf'
		#creat_tmoe_arch_file
		creat_container_edition_txt
		go_to_proot_management
		DISTRO_CODE='current'
		#sed '45 a\ARCH_TYPE="armhf"' |
		TUNA_LXC_IMAGE_MIRROR_REPO="https://mirrors.bfsu.edu.cn/gentoo/releases/arm64/autobuilds/current-stage3-arm64"
		TTIME=$(curl -L "${TUNA_LXC_IMAGE_MIRROR_REPO}/" | grep date | sed -E 's@<a (href)@\n\1@g' | awk -F 'href=' '{print $2}' | cut -d '"' -f 2 | egrep -v 'systemd|DIGESTS|CONTENTS.gz' | grep 'tar' | tail -n 1)
		bash -c "$(sed -n p ${TMOE_SHARE_DIR}/container/install |
			sed "s@\${TUNA_LXC_IMAGE_MIRROR_REPO}.*rootfs.tar.xz@${TUNA_LXC_IMAGE_MIRROR_REPO}/${TTIME}@g" |
			sed 's/debian system/Gentoo system/g' |
			sed 's:debian-sid:gentoo-current:g' |
			sed 's:debian/sid:gentoo/current:g' |
			sed 's:Debian GNU/Linux:Gentoo GNU/Linux:g')"
		;;
	*)
		creat_container_edition_txt
		go_to_proot_management
		DISTRO_CODE='current'
		linux_distro_common_model_01
		;;
	esac
}
###########################
install_alpine_linux_distro() {
	touch ~/.ALPINELINUXDetectionFILE
	DISTRO_NAME='alpine'
	#DISTRO_CODE='3.11'
	DISTRO_CODE=$(curl -L https://mirrors.bfsu.edu.cn/lxc-images/images/alpine/ | egrep -v 'edge|3.7|3.8|3.9' | grep date | tail -n 1 | cut -d '=' -f 3 | cut -d '"' -f 2 | sed 's@/@@')
	OLD_STABLE_VERSION='edge'
	which_version_do_you_want_to_install
}
#####################
opensuse_warning() {
	case "${LINUX_DISTRO}" in
	Android)
		case ${TMOE_CHROOT} in
		true) ;;
		*)
			cat <<-EOF
				${RED}WARNING！${RESET}检测到您使用的是Android系统。
				本镜像支持GNU/Linux的proot/chroot容器,但不支持termux-proot。
				经测试在termux的proot环境下存在无法检索到软件包的情况，但GNU/Linux的proot却不存在此问题。
				若您执意要安装OpenSUSE tumbleweed,则请按回车键。
			EOF
			do_you_want_to_continue
			;;
		esac
		;;
	esac
}
########
install_opensuse_linux_distro() {
	opensuse_warning
	DISTRO_NAME='opensuse'
	DISTRO_CODE='tumbleweed'
	TMOE_LINUX_CONTAINER_DISTRO='opensuse-tumbleweed'
	creat_container_edition_txt
	go_to_proot_management
	linux_distro_common_model_04
}
####################
install_raspios_linux_distro() {
	DISTRO_NAME='raspios'
	DISTRO_CODE='buster'
	TMOE_LINUX_CONTAINER_DISTRO="${DISTRO_NAME}-${DISTRO_CODE}"
	case "${ARCH_TYPE}" in
	arm64 | armhf) NEW_TMOE_ARCH='armhf' ;;
	*) distro_does_not_support ;;
	esac

	case "${TRUE_ARCH_TYPE}" in
	arm64 | armhf)
		TMOE_QEMU_ARCH=""
		creat_tmoe_arch_file
		;;
	esac
	ARCH_TYPE="${NEW_TMOE_ARCH}"
	creat_container_edition_txt
	go_to_proot_management
	#touch ~/.RASPBIANARMHFDetectionFILE
	printf "%s\n" "检测到您选择的是树莓派系统"
	printf "%s\n" "已将您的架构临时识别为armhf"
	printf "%s\n" "若您需要安装${YELLOW}arm64${RESET}版的树莓派系统，则请将arm64版的RaspiOS rootfs.tar.xz文件重命名为${GREEN}raspios-buster_armhf_lite-rootfs.tar.xz${RESET},并将其移动到${BLUE}${ROOTFS_DIR}${RESET}"
	if (whiptail --title "RASPIOS" --yes-button "FULL" --no-button "LITE" --yesno "您想要安装哪个版本的raspios？Full版约1.9G,lite版约274M" 9 50); then
		install_raspios_full_armhf_rootfs
	else
		install_raspios_lite_armhf_rootfs
	fi
}
###################
install_raspios_lite_armhf_rootfs() {
	bash -c "$(sed -n p ${TMOE_SHARE_DIR}/container/install |
		sed 's@TUNA_LXC_IMAGE_MIRROR_REPO=.*@TUNA_LXC_IMAGE_MIRROR_REPO=https://mirrors.bfsu.edu.cn/raspberry-pi-os-images/raspios_lite_armhf/archive@' |
		sed 's@${TTIME}rootfs.tar.xz@${TTIME}root.tar.xz@g' |
		sed 's@#deb http@deb http@g' |
		sed 's@-rootfs.tar.xz@_lite-rootfs.tar.xz@g' |
		sed 's/.*sid main/#&/' |
		sed 's/debian system/raspios system/g' |
		sed 's:debian-sid:raspios-buster:g' |
		sed 's:Debian GNU/Linux:Raspios GNU/Linux:g')"
}
##################
install_raspios_full_armhf_rootfs() {
	bash -c "$(sed -n p ${TMOE_SHARE_DIR}/container/install |
		sed 's@TUNA_LXC_IMAGE_MIRROR_REPO=.*@TUNA_LXC_IMAGE_MIRROR_REPO=https://mirrors.bfsu.edu.cn/raspberry-pi-os-images/raspios_full_armhf/archive@' |
		sed 's@${TTIME}rootfs.tar.xz@${TTIME}root.tar.xz@g' |
		sed 's@#deb http@deb http@g' |
		sed 's@-rootfs.tar.xz@_full-rootfs.tar.xz@g' |
		sed 's/.*sid main/#&/' |
		sed 's/debian system/raspios system/g' |
		sed 's:debian-sid:raspios-buster:g' |
		sed 's:Debian GNU/Linux:Raspios GNU/Linux:g')"
}
##################
install_manjaro_linux_distro() {
	case ${ARCH_TYPE} in
	arm64)
		touch ~/.MANJARO_ARM_DETECTION_FILE
		bash -c "$(sed -n p ${TMOE_SHARE_DIR}/container/install |
			sed 's@${TUNA_LXC_IMAGE_MIRROR_REPO}.*rootfs.tar.xz@https://mirrors.bfsu.edu.cn/osdn/storage/g/m/ma/manjaro-arm/.rootfs/Manjaro-ARM-aarch64-latest.tar.gz@g' |
			sed 's/debian system/manjaro system/g' |
			sed 's:debian-sid:manjaro-stable:g' |
			sed 's:debian/sid:manjaro/stable:g' |
			sed 's:rootfs.tar.xz:rootfs.tar.gz:g' |
			sed 's:Debian GNU/Linux:Manjaro GNU/Linux:g')"
		;;
	amd64)
		mkdir -pv ${ROOTFS_DIR}
		cd ${ROOTFS_DIR}
		MANJARO_ROOTFS_FILE_NAME="${DISTRO_NAME}-stable_${ARCH_TYPE}-rootfs.tar.xz"
		if [ ! -e "${MANJARO_ROOTFS_FILE_NAME}" ]; then
			TEMP_DIR=".MANJARO_AMD64-TEMP_FOLDER"
			[[ ! -e ${TEMP_DIR} ]] || rm -rfv ${TEMP_DIR}
			pwd
			git clone --depth=1 ${AK2_GIT_URL}/${DISTRO_NAME}-stable_${ARCH_TYPE}.git ${TEMP_DIR}
			cd ${TEMP_DIR}
			cat .container_linux_* >${MANJARO_ROOTFS_FILE_NAME}
			mv -fv ${MANJARO_ROOTFS_FILE_NAME} ../
			cd ..
			rm -rvf ${TEMP_DIR}
		fi
		bash -c "$(sed -n p ${TMOE_SHARE_DIR}/container/install |
			sed "s/debian system/${DISTRO_NAME} system/g" |
			sed "s:debian-sid:${DISTRO_NAME}-stable:g" |
			sed "s:Debian GNU/Linux:Manjaro GNU/Linux:g")"
		;;
	*)
		printf "%s\n" "SORRY,Tmoe-linux的开发者未对您的架构进行适配"
		distro_does_not_support
		#press_enter_to_return
		#install_beta_containers
		;;
	esac
}
#		sed 's@tar -pJxvf@tar -pzxvf@g'
############################
install_openwrt_linux_distro() {
	TMOE_LINUX_CONTAINER_DISTRO='openwrt'
	DISTRO_NAME='openwrt'
	creat_container_edition_txt
	go_to_proot_management
	touch ~/.ALPINELINUXDetectionFILE
	CONTAINER_REPO='https://mirrors.bfsu.edu.cn/openwrt/releases/'
	THE_LATEST_VERSION=$(curl -L ${CONTAINER_REPO} | egrep -v 'faillog|packages' | grep 'href' | tail -n 1 | cut -d '=' -f 3 | cut -d '"' -f 2 | cut -d '/' -f 1)
	THE_LATEST_ROOTFS_REPO="${CONTAINER_REPO}${THE_LATEST_VERSION}/targets/"
	case "${ARCH_TYPE}" in
	"amd64") THE_LATEST_ISO_LINK="${THE_LATEST_ROOTFS_REPO}x86/64/openwrt-${THE_LATEST_VERSION}-x86-64-generic-rootfs.tar.gz" ;;
	'i386') THE_LATEST_ISO_LINK="${THE_LATEST_ROOTFS_REPO}x86/generic/openwrt-${THE_LATEST_VERSION}-x86-generic-generic-rootfs.tar.gz" ;;
	"arm64") THE_LATEST_ISO_LINK="${THE_LATEST_ROOTFS_REPO}armvirt/64/openwrt-${THE_LATEST_VERSION}-armvirt-64-default-rootfs.tar.gz" ;;
	"armhf") THE_LATEST_ISO_LINK="${THE_LATEST_ROOTFS_REPO}armvirt/32/openwrt-${THE_LATEST_VERSION}-armvirt-32-default-rootfs.tar.gz" ;;
	esac
	bash -c "$(sed -n p ${TMOE_SHARE_DIR}/container/install |
		sed "s@\${TUNA_LXC_IMAGE_MIRROR_REPO}.*rootfs.tar.xz@${THE_LATEST_ISO_LINK}@g" |
		sed 's/debian system/openwrt system/g' |
		sed 's:debian-sid:openwrt-latest:g' |
		sed 's:debian/sid:openwrt/snapshot:g' |
		sed 's@tar -pJx@tar -pzx@g' |
		sed 's:Debian GNU/Linux:OpenWRT Linux:g')"
}
######################
install_devuan_linux_distro() {
	CLOUD_ROOTFS='true'
	DISTRO_NAME='devuan'
	#DISTRO_CODE='beowulf'
	#OLD_STABLE_VERSION=$(curl -L https://mirrors.bfsu.edu.cn/lxc-images/images/devuan/ | grep date | tail -n 2 | head -n 1 | cut -d '=' -f 4 | cut -d '"' -f 2)
	OLD_STABLE_VERSION=ascii
	check_the_latest_distro_version
}
######################
install_slackware_linux_distro() {
	DISTRO_NAME='slackware'
	TMOE_LINUX_CONTAINER_DISTRO='slackware'
	creat_container_edition_txt
	[[ -e ${ROOTFS_DIR} ]] || mkdir -pv ${ROOTFS_DIR}
	cd ${ROOTFS_DIR}
	#touch .SLACKDetectionFILE
	case "${ARCH_TYPE}" in
	amd64)
		go_to_proot_management
		if [ ! -e "slackware-current_amd64-rootfs.tar.xz" ]; then
			git clone -b x64 --depth=1 ${AK2_GIT_URL}/slackware_rootfs.git .SLACKWARE_AMD64_TEMP_FOLDER
			#aria2c --console-log-level=warn --no-conf -x 16 -s 16 -k 1M -o "slackware-current-rootfs.tar.xz" "https://cdn.tmoe.me/Tmoe-Debian-Tool/chroot/archive/slackware_amd64.tar.xz" || aria2c --console-log-level=warn --no-conf -x 16 -s 16 -k 1M -o "slackware-current-rootfs.tar.xz" "https://m.tmoe.me/down/share/Tmoe-linux/chroot/slackware_amd64.tar.xz"
			cd .SLACKWARE_AMD64_TEMP_FOLDER
			mv -f slackware_amd64.tar.xz ../slackware-current_amd64-rootfs.tar.xz
			cd ..
			rm -rf .SLACKWARE_AMD64_TEMP_FOLDER
		fi
		bash -c "$(sed -n p ${TMOE_SHARE_DIR}/container/install |
			sed 's/debian system/slackware system/g' |
			sed 's:debian-sid:slackware-current:g' |
			sed 's:debian/sid:slackware/current:g' |
			sed 's:Debian GNU/Linux:Slackware GNU/Linux:g')"
		;;
	arm64 | armhf)
		NEW_TMOE_ARCH='armhf'
		TMOE_QEMU_ARCH=""
		creat_tmoe_arch_file
		ARCH_TYPE='armhf'
		go_to_proot_management
		#if [ ! -e "slackware-current_armhf-rootfs.tar.xz" ]; then
		printf "%s\n" "检测到您当前使用的是${ARCH_TYPE}架构，将为您安装armhf版slackware容器"
		SLACKWARE_ROOTFS_TUNA_REPO='https://mirrors.bfsu.edu.cn/slackwarearm/slackwarearm-devtools/minirootfs/roots'
		LatestSlack="$(curl -L ${SLACKWARE_ROOTFS_TUNA_REPO}/ | grep 'tar.xz' | tail -n 1 | cut -d '=' -f 3 | cut -d '"' -f 2)"
		#aria2c --console-log-level=warn --no-conf -x 5 -s 5 -k 1M -o "slackware-current_armhf-rootfs.tar.xz" "${SLACKWARE_ROOTFS_TUNA_REPO}/${LatestSlack}"
		#fi
		THE_LATEST_SLACKWARE_URL="${SLACKWARE_ROOTFS_TUNA_REPO}/${LatestSlack}"
		bash -c "$(sed -n p ${TMOE_SHARE_DIR}/container/install |
			sed "s@\${TUNA_LXC_IMAGE_MIRROR_REPO}.*rootfs.tar.xz@${THE_LATEST_SLACKWARE_URL}@g" |
			sed 's/debian system/slackware system/g' |
			sed 's:debian-sid:slackware-current:g' |
			sed 's:debian/sid:slackware/current:g' |
			sed 's:Debian GNU/Linux:Slackware GNU/Linux:g')"
		;;
	*) distro_does_not_support ;;
	esac
}
#########################
distro_does_not_support() {
	printf "%s\n" "${PURPLE}Sorry${RESET},your architecture is ${BLUE}${ARCH_TYPE}${RESET}."
	printf "%s\n" "检测到您使用的是${BLUE}${ARCH_TYPE}${RESET}架构,请尝试${YELLOW}跨架构${RESET}运行,或换用其他发行版"
	press_enter_to_return
	choose_which_gnu_linux_distro
}
##############
install_armbian_linux_distro() {
	RETURN_TO_WHERE='install_armbian_linux_distro'
	DISTRO_NAME='armbian'
	BETA_SYSTEM=$(
		whiptail --title "Which version do you want to install?" --menu "armbian是专为ARM开发板(例如nanopi,rock64,pine64等)打造的debian/ubuntu系统。\n以下系统已预装桌面,每个镜像大小约为1G" 0 50 0 \
			"1" "🐎 Bullseye(debian 11)" \
			"2" "🦍 Groovy Gorilla(ubuntu 20.10)" \
			"3" "🐱 Focal Fossa(ubuntu 20.04)" \
			"4" "Custom code手动输入版本代号" \
			"5" "🐶 Buster(debian 10)" \
			"6" "Bionic Beaver仿生海狸(ubuntu 18.04)" \
			"0" "🌚 Return to previous menu 返回上级菜单" \
			3>&1 1>&2 2>&3
	)
	##############################
	case "${BETA_SYSTEM}" in
	0 | "") choose_which_gnu_linux_distro ;;
	1) DISTRO_CODE='bullseye' ;;
	2) DISTRO_CODE='groovy' ;;
	3) DISTRO_CODE='focal' ;;
	4) custom_armbian_version ;;
	5) DISTRO_CODE='buster' ;;
	6) DISTRO_CODE='bionic' ;;
	esac
	######################
	case "${ARCH_TYPE}" in
	arm64 | armhf) ;;
	*) distro_does_not_support ;;
	esac
	TMOE_LINUX_CONTAINER_DISTRO="${DISTRO_NAME}-${DISTRO_CODE}"
	creat_container_edition_txt
	go_to_proot_management
	printf "%s\n" "即将为您安装${TMOE_LINUX_CONTAINER_DISTRO} GNU/Linux container"
	do_you_want_to_continue
	install_different_armbian_gnu_linux_distros
	####################
	exit 0
}
#########################
install_different_armbian_gnu_linux_distros() {
	if [ ! $(command -v lz4) ]; then
		apt update 2>/dev/null
		apt install -y lz4 2>/dev/null || pacman -Syu --noconfirm lz4 2>/dev/null || zypper in -y lz4 2>/dev/null
	fi
	ARMBIAN_TUNA_REPO='https://mirrors.bfsu.edu.cn/armbian-releases/_rootfs'
	ARMBIAN_ROOTFS_FILE="$(curl -L ${ARMBIAN_TUNA_REPO}/ | grep "${DISTRO_CODE}-xfce-desktop" | egrep -v '\.tar\.lz4\.asc|\.torrent|\.lz4\.list' | grep ${ARCH_TYPE} | head -n 1 | cut -d '=' -f 3 | cut -d '"' -f 2)"
	ARMBIAN_ROOTFS_URL="${ARMBIAN_TUNA_REPO}/${ARMBIAN_ROOTFS_FILE}"
	case "${DISTRO_CODE}" in
	squeeze | wheezy | jessie | stretch | buster) install_armbian_buster_via_tuna ;;
	*) install_armbian_testing_via_tuna ;;
	esac
}
########
install_armbian_buster_via_tuna() {
	bash -c "$(sed -n p ${TMOE_SHARE_DIR}/container/install |
		sed "s@\${TUNA_LXC_IMAGE_MIRROR_REPO}.*rootfs.tar.xz@${ARMBIAN_ROOTFS_URL}@g" |
		sed "s/focal/${DISTRO_CODE}/g" |
		sed 's@rootfs.tar.xz@rootfs.tar.lz4@g' |
		sed "s/debian system/${DISTRO_NAME} system/g" |
		sed "s:debian-sid:${DISTRO_NAME}-${DISTRO_CODE}:g" |
		sed 's@#deb http@deb http@g' |
		sed 's/.*sid main/#&/' |
		sed "s@stable/updates@${DISTRO_CODE}/updates@g" |
		sed "s@buster-backports@${DISTRO_CODE}-backports@g" |
		sed "s@debian/ stable@debian/ ${DISTRO_CODE}@g" |
		sed "s:Debian GNU/Linux:${DISTRO_NAME} GNU/Linux:g")"
}
###########
install_armbian_testing_via_tuna() {
	bash -c "$(sed -n p ${TMOE_SHARE_DIR}/container/install |
		sed "s@\${TUNA_LXC_IMAGE_MIRROR_REPO}.*rootfs.tar.xz@${ARMBIAN_ROOTFS_URL}@g" |
		sed "s/focal/${DISTRO_CODE}/g" |
		sed 's@rootfs.tar.xz@rootfs.tar.lz4@g' |
		sed "s/debian system/${DISTRO_NAME} system/g" |
		sed "s:debian-sid:${DISTRO_NAME}-${DISTRO_CODE}:g" |
		sed 's@#deb http@deb http@g' |
		sed 's/.*sid main/#&/' |
		sed "s@stable/updates@${DISTRO_CODE}-security@g" |
		sed "s@buster-backports@${DISTRO_CODE}-backports@g" |
		sed "s@debian/ stable@debian/ ${DISTRO_CODE}@g" |
		sed "s:Debian GNU/Linux:${DISTRO_NAME} GNU/Linux:g")"
}
###########
custom_armbian_version() {
	TARGET=$(whiptail --inputbox "请输入armbian版本代号，例如bullseye(英文小写)\nPlease type the armbian version code." 9 50 --title "ARMBIAN CODE" 3>&1 1>&2 2>&3)
	DISTRO_CODE="$(printf '%s\n' "${TARGET}" | head -n 1 | cut -d ' ' -f 1)"
	if [ -z "${DISTRO_CODE}" ]; then
		printf "%s\n" "检测到您取消了操作"
		printf "%s\n" "已自动切换为armbian bullseye"
		DISTRO_CODE='bullseye'
	fi
}
###########
install_mint_linux_distro() {
	case ${ARCH_TYPE} in
	amd64 | i386) which_linux_mint_distro ;;
	*)
		printf "%s\n" "${RED}WARNING！${RESET}检测到您使用的是${ARCH_TYPE}架构"
		printf "%s\n" "Linux Mint${RED}不支持${RESET}您的架构"
		printf "%s\n" "请换用${YELLOW}amd64${RESET}或${YELLOW}i386${RESET}设备后，再来尝试"
		press_enter_to_return
		install_beta_containers
		;;
	esac
}
################
check_mint_version_code() {
	DISTRO_NAME='mint'
	OLD_STABLE_VERSION='tricia'
	LXC_IMAGES_REPO="https://mirrors.bfsu.edu.cn/lxc-images/images/${DISTRO_NAME}/"
	DISTRO_CODE=$(curl -sL ${LXC_IMAGES_REPO} | grep date | cut -d '=' -f 4 | cut -d '"' -f 2 | egrep -v 'size|sarah|serena|sonya|sylvia|tara|tessa|tina|tricia|ulyana' | tail -n 1)
}
###########
which_linux_mint_distro() {
	RETURN_TO_WHERE='which_linux_mint_distro'
	DISTRO_NAME='mint'
	BETA_SYSTEM=$(
		whiptail --title "mint" --menu "您想要安装哪个Mint版本？\nWhich version do you want to install?\nIf you are using i386,then choose tricia." 0 0 0 \
			"1" "Auto check 自动检测版本" \
			"2" "Custom code手动输入版本代号" \
			"0" "🌚 Return to previous menu 返回上级菜单" \
			3>&1 1>&2 2>&3
	)
	##############################
	case "${BETA_SYSTEM}" in
	0 | "") choose_which_gnu_linux_distro ;;
	1)
		check_mint_version_code
		which_version_do_you_want_to_install
		;;
	2) custom_mint_version ;;
	esac
	######################
	press_enter_to_return
	tmoe_manager_main_menu
}
#########################
custom_mint_version() {
	TARGET=$(whiptail --inputbox "请输入mint版本代号，例如ulyana(英文小写)\n Please enter the mint version code." 12 50 --title "MINT CODE" 3>&1 1>&2 2>&3)
	DISTRO_CODE="$(printf '%s\n' "${TARGET}" | head -n 1 | cut -d ' ' -f 1)"
	if [ -z "${DISTRO_CODE}" ]; then
		printf "%s\n" "检测到您取消了操作"
		printf "%s\n" "已自动切换为ulyana"
		DISTRO_CODE='ulyana'
	fi
	before_going_to_proot_menu
	printf "%s\n" "即将为您安装Mint ${DISTRO_CODE} GNU/Linux container"
	do_you_want_to_continue
	linux_distro_common_model_01
}
######################
